$(function(){

    //下面这封装好的函数是获取URL中参数值的方法:
    (function($){
        $.getUrlParam = function(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }
    })(jQuery);

    // 页面初始化....将这个商品的id传递到函数当中获取接口中的数据...
    showData( $.getUrlParam('commondityId') );

    // 封装好的一个函数,,,用来回显接口当中的数据到页面当中........
    function showData(commondityId)
    {

        $.ajax({
            type:'post',
            async:false,
            headers: {"Accept-CMS-Token":token},
            url:shopcommondityone,
            dataType:'json',
            data:{
                commondityId:commondityId
            },
            success:successFn,
            error:function(){
                console.log('获取省接口请求失败');
            },
        });

    };

    // 调回显数据的接口请求成功之后,,,执行此函数...
    function successFn(data)
    {
        if(data.resultCode == 200)
        {
            var value = data.value.shopCommodity;

            // 将后台返回来的数据取其中一条...回显到页面当中...
            $('dl.number').append('<dd class="fl">'+value.number+'</dd>');

            $('dl.name').append('<dd class="fl">'+value.name+'</dd>');

            $('dl.price').append('<dd class="fl">'+value.price+'</dd>');

            $('dl.totalNum').append('<dd class="fl">'+value.totalNum+'</dd>');

            $('dl.modelName').append('<dd class="fl">'+value.modelName+'</dd>');

            $('dl.company').append('<dd class="fl">'+value.company+'</dd>');

            //回显颜色中的数据
            $('.getColor').append('<dd class="fl project_width"><label><input type="radio" name="color" value="'+value.colorId+'" class="project" description="'+value.colorName+'" checked>'+value.colorName+'</label></dd>');
            // 回显尺寸当中的数据
            $('.getSize').append('<dd class="fl project_width"><label><input type="radio" name="size" value="'+value.sizeId+'" class="project" description="'+value.sizeName+'" checked>'+value.sizeName+'</label></dd>');

            // 标签回显
            var lableIdArr = value.lableId.split(',');
            var lableNameArr = value.lableName.split(',');
            if(lableIdArr.length == 1)
            {
                $('.getTag').append('<dd class="fl project_width"><label><input type="checkbox" name="tag" value="'+lableIdArr[0]+'" class="project" description="'+lableNameArr[0]+'" checked>'+lableNameArr[0]+'</label></dd>');
            }
            else
            {
                for(var m=0;m<(lableIdArr.length-1);m++)
                {
                    $('.getTag').append('<dd class="fl project_width"><label><input type="checkbox" name="tag" value="'+lableIdArr[m]+'" class="project" description="'+lableNameArr[m]+'" checked>'+lableNameArr[m]+'</label></dd>');
                };
            };
            // console.log(lableIdArr)
            //状态回显
            if( value.status == 1 )
            {
                $('dl.status').append('<dd class="fl">正常</dd>');
            }
            else
            {
                $('dl.status').append('<dd class="fl">售罄</dd>');
            };

            // 产地----省回显
            $('dl.province').append('<dd class="fl">'+value.areaProvinceName+'-'+value.areaCityName+'</dd>');
            // 规格回显
            $('dl.guiGe').append('<dd class="fl">'+value.specificationName+'</dd>');
            // 回显封面图片
            $('.wrap_fengMian div div img').attr( 'src',address + value.coverUrl );
            $('.wrap_fengMian div div img').attr( 'height',300 );
            $('input[name = coverUrl]').val( value.coverUrl );
            // 图文详情回显数据
            var imgDetailArr = value.detailUrl.split(',');
            if(imgDetailArr.length == 1)
            {
                $('.wrap_datail div div').append('<img src="'+address + imgDetailArr[0]+'" width="230" height="150">');
            }
            else
            {
                for( var x=0;x<(imgDetailArr.length-1);x++ )
                {
                    $('.wrap_datail div div').append('<img src="'+address + imgDetailArr[x]+'" width="230" height="150">');
                };
            };
            $('input[name = detailUrl]').val( value.detailUrl );
            // 产品参数回显数据
            var base = new Base64();
            var commodity = JSON.parse( base.decode(value.commodity) ) ;
            for( var key in commodity ){

                $('.productPara tbody').append( '<tr><th><input type="text" value="'+ key +'" class="font_white param_name" placeholder="请输入"></th><td><input type="text" value="' + commodity[key] + '" placeholder="请输入" class="param_value"></td></tr>' );

            };



            // 回显简介下面的textarea
            $('dl.info').append('<dd class="fl">'+value.info+'</dd>');

            $('dl.packingList').append('<dd class="fl">'+value.packingList+'</dd>');

            $('dl.afterSalesService').append('<dd class="fl">'+value.afterSalesService+'</dd>');

            $('dl.useing').append('<dd class="fl">'+value.useing+'</dd>');

            console.log('获取省接口调通!!!!');
        }
        else if(data.resultCode == 515)
        {
            reLogin();
        }
    };



})
